package com.bx.scala.ObjextFoundation06

class Person(val name: String) {
  def sayHi = s"Hi everyone, I'm ${name}."
}

object DemoPerson {
  def main(args: Array[String]): Unit = {
    val tom = new Person("Tom") // 常规的类的实例化
    println(tom.sayHi)
    println("#" * 20)
    val jerry = new Person("Jerry") {
      override def sayHi: String = "Hey ther"
      def gettings = s"Greetings everybody, I'm ${name}"
    }
    println(jerry.sayHi)
    println(jerry.gettings)
    println(jerry.isInstanceOf[Person])
    println("#" * 20)

    def testFunc(p: Person {def sayHi: String; def gettings: String}): Unit = {
      println(s"SayHi: ${p.sayHi}, greetings: ${p.gettings}")
    }
    testFunc(jerry)
  }
}
